package com.awspaas.user.apps.sts.service;

import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.bpmn.engine.model.def.UserTaskModel;
import com.actionsoft.bpms.bpmn.engine.model.def.ext.CommentModel;
import com.actionsoft.bpms.bpmn.engine.model.run.TaskCommentTempModel;
import com.actionsoft.bpms.bpmn.engine.model.run.delegate.HistoryTaskInstance;
import com.actionsoft.bpms.bpmn.engine.model.run.delegate.ProcessInstance;
import com.actionsoft.bpms.bpmn.engine.model.run.delegate.TaskInstance;
import com.actionsoft.bpms.client.notification.NotificationMessageFormatter;
import com.actionsoft.bpms.commons.database.RowMap;
import com.actionsoft.bpms.commons.mvc.view.ActionWeb;
import com.actionsoft.bpms.commons.mvc.view.ResponseObject;
import com.actionsoft.bpms.server.UserContext;
import com.actionsoft.bpms.util.DBSql;
import com.actionsoft.sdk.local.SDK;
import com.actionsoft.sdk.local.api.AppAPI;
import com.actionsoft.sdk.local.api.ProcessExecuteQuery;
import com.actionsoft.sdk.service.model.TaskComment;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.awspaas.user.apps.publicservice.bean.*;
import com.awspaas.user.apps.publicservice.util.SendWechatMsgUtil;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;


/**
 * @Title: STSService
 * @Package com.awspaas.user.apps.sts.service
 * @Author wanglx
 * @Date 2022/8/4
 */
public class STSService extends ActionWeb {

    /**启动流程任务(非FTS)
     * @return*/
    public ResponseData startProcess(RequestData requestData){
        //流程创建人ID
        String targetUid = requestData.getTargetUid();
        //流程标题
        String outerTitle = requestData.getProcessTitle();
        //扩展信息
        Map<String, String> extInfo = requestData.getExtInfo();
        //流程定义ID
        String outerProcessDefId = requestData.getOuterProcessDefId();

        ProcessInstance processInstance = SDK.getProcessAPI().createProcessInstance(outerProcessDefId, targetUid, outerTitle);

        SDK.getProcessAPI().start(processInstance);

        ResponseData responseData = new ResponseData();

        //获取首环节任务实例
        TaskInstance taskInstance = SDK.getTaskAPI().getTaskInstance(processInstance.getStartTaskInstId());
        //完成首环节任务
        UserContext userContext = UserContext.fromUID(targetUid);
        ProcessExecuteQuery processExecuteQuery = SDK.getTaskAPI().completeTask(taskInstance, userContext,true);
        if (!processExecuteQuery.isProcessEnd()) {
            List<TaskInstance> taskInstances = processExecuteQuery.fetchActiveTasks();
            for (TaskInstance nextTaskInstance : taskInstances) {
                //流程版本ID
                responseData.setProcess_VerID(processInstance.getProcessDefVerId());
                //流程定义ID
                responseData.setProcess_DefId(processInstance.getProcessDefId());
                //流程实例ID
                responseData.setProcess_InstID(processInstance.getId());
                //待办ID
                responseData.setOuterId(nextTaskInstance.getId());

                //业务线索ID businessLeadsID
            }
        }

        return  responseData;
    }


    /**启动流程任务（FTS）
     * @return*/
    public ResponseData startProcess(RequestData requestData,AwsLog awsLog,Response response){
        ResponseData responseData = new ResponseData();

        //流程创建人ID
        String targetUid = requestData.getTargetUid();
        //流程标题
        String outerTitle = requestData.getProcessTitle();
        //扩展信息
        Map<String, String> extInfo = requestData.getExtInfo();
        //流程定义ID
        String outerProcessDefId = requestData.getOuterProcessDefId();
        ProcessInstance processInstance =null;
        int num=0;
        num = DBSql.getInt("SELECT COUNT(*) FROM ORGUSER WHERE USERID = ? OR USERNO = ?",new Object[]{targetUid,targetUid});

        try {

             processInstance = SDK.getProcessAPI().createProcessInstance(outerProcessDefId, targetUid, outerTitle);
            ResponseCode successRC = ResponseCode.SUCCESS_RESPONSE;
            response.setCode(successRC.getCode());
            response.setDesc(successRC.getDesc());
            responseData.setProcess_InstID(processInstance.getId());
            responseData.setProcess_VerID(processInstance.getProcessDefVerId());
            responseData.setProcess_DefId(processInstance.getProcessDefId());
            response.setData(responseData);
            awsLog.end(AwsLog.SUCCESS, response);
        }catch (Exception e){
            e.printStackTrace();
            ResponseCode failRC = ResponseCode.FAIL_EXCEPTION;
            response.setCode(failRC.getCode());
            response.setDesc(failRC.getDesc());
            response.setData(responseData);
            awsLog.end(AwsLog.ERROR, response);
        }
        finally{
            // 将错误信息存储至接口日志表中
            BO awsBo = awsLog.getBo();
            if(awsBo != null) {
                awsBo.set("INTERFACE_PARAMETER",requestData.toString());
              //  awsBo.set("OUTPARAMETER",response.toString());

                // 创建一条流程实例，用于存储DW查看
                ProcessInstance createBOProcessInstance = SDK.getProcessAPI().createBOProcessInstance("obj_d778147f5b9741138b427effafce0753", targetUid, targetUid + "在"
                        + AwsLog.sdf.format(awsLog.getCallStartTime()) + "调用了TASKSYNC.startProcess接口");
                if (num == 0) {
                    SDK.getBOAPI().create("BO_EU_INTERFACE_LOG", awsBo, createBOProcessInstance.getId(), "admin");
                } else {
                    SDK.getBOAPI().create("BO_EU_INTERFACE_LOG", awsBo, createBOProcessInstance.getId(), targetUid);
                }
            }else{
                awsBo.set("INTERFACE_PARAMETER",requestData.toString());
               // awsBo.set("OUTPARAMETER",response.toString());

                // 创建一条流程实例，用于存储DW查看
                ProcessInstance createBOProcessInstance = SDK.getProcessAPI().createBOProcessInstance("obj_d778147f5b9741138b427effafce0753", targetUid, targetUid + "在"
                        + AwsLog.sdf.format(awsLog.getCallStartTime()) + "调用了TASKSYNC.startProcess接口");
                if (num == 0) {
                    SDK.getBOAPI().create("BO_EU_INTERFACE_LOG", awsBo, createBOProcessInstance.getId(), "admin");
                } else {
                    SDK.getBOAPI().create("BO_EU_INTERFACE_LOG", awsBo, createBOProcessInstance.getId(), targetUid);
                }
            }
        }


        SDK.getProcessAPI().start(processInstance);



        //获取首环节任务实例
        TaskInstance taskInstance = SDK.getTaskAPI().getTaskInstance(processInstance.getStartTaskInstId());
        //完成首环节任务
        UserContext userContext = UserContext.fromUID(targetUid);
        ProcessExecuteQuery processExecuteQuery = SDK.getTaskAPI().completeTask(taskInstance, userContext,true);
        if (!processExecuteQuery.isProcessEnd()) {
            List<TaskInstance> taskInstances = processExecuteQuery.fetchActiveTasks();
            for (TaskInstance nextTaskInstance : taskInstances) {
                //流程版本ID
                responseData.setProcess_VerID(processInstance.getProcessDefVerId());
                //流程定义ID
                responseData.setProcess_DefId(processInstance.getProcessDefId());
                //流程实例ID
                responseData.setProcess_InstID(processInstance.getId());
                //待办ID
                responseData.setOuterId(nextTaskInstance.getId());

                //业务线索ID businessLeadsID
            }
        }

        return  responseData;

    }


    /**办理流程任务
     * @return*/
    public ResponseData completeProcess(RequestData requestData, TaskInstance taskInstance,AwsLog awsLog){

        // System.out.println("任务实例数据：" + taskInstance.toString());
        Response response = new Response();
        //任务实例ID
        String outerId = taskInstance.getId();
        //办理人ID
        String targetUid = taskInstance.getTarget();
        //操作
        String actionName = requestData.getActionName();
        //扩展信息
        Map<String, String> extInfo = requestData.getExtInfo();
        //任务标题
        String outerTitle = requestData.getTaskTitle();

        // System.out.println("任务标题：" + outerTitle);
        TaskCommentTempModel commentTempModel = SDK.getTaskAPI().getCommentOfTemp(outerId);
        String commentMsg = null;
        if (null!=commentTempModel) {
            commentMsg = commentTempModel.getMsg();
        }

        ResponseData responseData = new ResponseData();
        responseData.setProcess_InstID(taskInstance.getProcessInstId());

        List<TaskInstance> taskInstances = new ArrayList<>();
        if (actionName.equals("through")) {
            // System.out.println("办理前.....");
            responseData = completeTask(outerId, targetUid, outerTitle, taskInstances);
            System.out.println("办理完成：" + responseData);
        } else if (actionName.equals("reject")) {
            responseData = rollbackTask(outerId, targetUid, commentMsg);
        } else if(actionName.equals("cancel")){
            responseData = cancelTask(taskInstance, targetUid, commentMsg);
        }else{
            response.setCode("500");
            response.setDesc("没有选择正确的审核菜单：" + actionName);
            response.setData(responseData);
            awsLog.end(AwsLog.ERROR, response);
        }

        return  responseData;
    }

    /**
     * @methodName:
     * @param:
     * @return:
     * @description:完成任务
     * @auther: Lizj
     * @date: 2022/8/29 0:58
     */
    public ResponseData completeTask(String outerId, String targetUid, String outerTitle, List<TaskInstance> taskInstances) {
        ResponseData responseData = new ResponseData();
        TaskInstance taskInstance = SDK.getTaskAPI().getTaskInstance(outerId);
        int a = 0;
        // 流程自动向下流转,获取下一节点流程信息
        ProcessExecuteQuery completeTask = SDK.getTaskAPI().completeTask(outerId,targetUid,true);
        String processInstId = taskInstance.getProcessInstId();
        if (!SDK.getProcessAPI().isEndById(processInstId)) {
            // 查询流程引擎全部的执行结果
            taskInstances = completeTask.fetchAllTasks();
            if (null != taskInstances && !taskInstances.isEmpty()) {
                for (TaskInstance nextTaskInstance : taskInstances) {

                    // 判断是否是人工任务
                    String owner = nextTaskInstance.getOwner();

                    if(owner != "" && owner != null){
                        String nextTaskInstId = nextTaskInstance.getId();
                        if (null!=outerTitle && !outerTitle.equals("")) {
                            // System.out.println("流程待办标题：" + outerTitle);
                            // System.out.println("根据下一环节任务实例ID获取到的流程实例ID：" + nextTaskInstance.getProcessInstId());
                            // System.out.println("下一环节任务实例ID：" + nextTaskInstance.getId());
                            // int update = DBSql.update("UPDATE WFC_PROCESS SET PROCESSTITLE = ? WHERE ID = ?", new Object[]{outerTitle, nextTaskInstance.getProcessInstId()});
                            // System.out.println("已修改：" + update);
                            SDK.getProcessAPI().setTitle(nextTaskInstance.getProcessInstId(),outerTitle);
                            SDK.getTaskAPI().setTitle(nextTaskInstance.getId(),outerTitle);
                        }
                        String nextTargetUid = nextTaskInstance.getTarget();
                        //流程定义Id
                        String processDefIdOfNext = nextTaskInstance.getProcessDefId();
                        //节点定义Id
                        String nodeCode = nextTaskInstance.getActivityDefId();
                        //获取人工任务模型
                        UserTaskModel userTaskModel = SDK.getRepositoryAPI().getUserTaskModel(processDefIdOfNext, nodeCode);
                        //获取审批菜单List
                        List<ApproveMenu> approveMenus = getApproveMenu(userTaskModel);

                        //人工任务模型名称
                        String nodeName = userTaskModel.getName();
                        //下一个节点的任务标题
                        String title = nextTaskInstance.getTitle();
                        // System.out.println("title" + title);
                        responseData.setOuterId(nextTaskInstId);
                        responseData.setTargetUid(nextTargetUid);
                        responseData.setNodeCode(nodeCode);
                        //节点名称
                        responseData.setNodeName(nodeName);
                        //set任务标题
                        responseData.setTitle(outerTitle);
                        //流程ID
                        String nextProcessInstId = nextTaskInstance.getProcessInstId();
                        // SDK.getProcessAPI().setTitle(nextProcessInstId,nodeName);
                        responseData.setApproveMenu(approveMenus);
                    }
                }
            }
        }
        return responseData;
    }
    /**
     * @methodName:
     * @param:
     * @return:
     * @description:取消任务
     * @auther: Lizj
     * @date: 2022/8/29 0:58
     */
    public ResponseData cancelTask(TaskInstance taskInstance, String targetUid, String commentMsg) {
        ResponseData responseData = new ResponseData();
        if (null!=commentMsg && !commentMsg.equals("")) {
            SDK.getTaskAPI().cancelTask(taskInstance,targetUid,commentMsg);
        } else {
            commentMsg = "取消任务";
            SDK.getTaskAPI().cancelTask(taskInstance,targetUid,commentMsg);
        }
        return null;
    }
    /**
     * @methodName:
     * @param:
     * @return:
     * @description:回退任务
     * @auther: Lizj
     * @date: 2022/8/29 0:58
     */
    public ResponseData rollbackTask(String outerId, String targetUid, String commentMsg) {
        ResponseData responseData = new ResponseData();
        //查找当前流程已经办理过得历史节点
        HistoryTaskInstance lastUserTask = SDK.getTaskAPI().findUserTaskByPrePath(outerId);
        String lastActivityDefId = lastUserTask.getActivityDefId();

        //回退上一节点（待用）
        TaskInstance lastTaskInstance = null;
        if (null!=commentMsg && !commentMsg.equals("")) {
            lastTaskInstance = SDK.getTaskAPI().rollbackTask(outerId, lastActivityDefId, targetUid, true, commentMsg);
        } else {
            commentMsg = "驳回任务";
            lastTaskInstance = SDK.getTaskAPI().rollbackTask(outerId, lastActivityDefId, targetUid, true, commentMsg);
        }
        String processDefIdOfNext = lastTaskInstance.getProcessDefId();
        String nodeCode = lastTaskInstance.getActivityDefId();

        UserTaskModel userTaskModel = SDK.getRepositoryAPI().getUserTaskModel(processDefIdOfNext, nodeCode);
        List<ApproveMenu> approveMenus = getApproveMenu(userTaskModel);
        String nodeName = userTaskModel.getName();
        //任务标题
        String title = lastTaskInstance.getTitle();
        String lastTaskInstId = lastTaskInstance.getId();
        String lastTargetUid = lastTaskInstance.getTarget();
        responseData.setOuterId(lastTaskInstId);
        responseData.setTargetUid(lastTargetUid);
        responseData.setNodeCode(nodeCode);
        //节点名称
        responseData.setNodeName(nodeName);
        //set任务标题
        responseData.setTitle(title);
        responseData.setApproveMenu(approveMenus);
        return responseData;
    }

    /**
     * @methodName:
     * @param:
     * @return:
     * @description:获取审批菜单List
     * @auther: Lizj
     * @date: 2022/8/29 0:47
     */
    public List<ApproveMenu> getApproveMenu(UserTaskModel userTaskModel) {
        //人工流程定义id
        String processDefId = userTaskModel.getProcessDefId();
        //返回审核菜单模型列表
        List<CommentModel> commentModels = userTaskModel.getCommentModels();
        //审批菜单list
        ArrayList<ApproveMenu> approveMenus = new ArrayList<>();
        if (null!=commentModels) {
            for (CommentModel commentModel : commentModels) {
                ApproveMenu approveMenu = new ApproveMenu();
                //编码
                String commentId = commentModel.getId();
                //名称
                String commentName = commentModel.getActionName();
                //可驳回节点
                String targetDefIds = commentModel.getTargetDefId();
                //
                ArrayList<String> targetDefIdList = new ArrayList<>();
                //
                ArrayList<Map<String, String>> rejectList = new ArrayList<>();
                if (null != targetDefIds && !targetDefIds.equals("")) {
                    //判断是否有%
                    if (targetDefIds.contains("%")) {
                        String[] targetDefIdsSplit1 = targetDefIds.split("%");
                        for (String targetDefIdSplit1 : targetDefIdsSplit1) {
                            if (targetDefIdSplit1.contains("|")) {
                                String[] targetDefIdsSplit2 = targetDefIdSplit1.split("\\|");
                                for (String targetDefIdSplit2 : targetDefIdsSplit2) {
                                    targetDefIdList.add(targetDefIdSplit2);
                                }
                            } else {
                                if (null != targetDefIdSplit1 && !targetDefIdSplit1.equals("")) {
                                    targetDefIdList.add(targetDefIdSplit1);
                                }
                            }
                        }
                    } else {
                        targetDefIds = targetDefIds.replace("|", "");
                        targetDefIdList.add(targetDefIds);
                    }
                }
                HashSet<String> targetDefIdSet = new HashSet<>();
                targetDefIdSet.addAll(targetDefIdList);
                targetDefIdList.clear();
                targetDefIdList.addAll(targetDefIdSet);
                for (String targetDefId : targetDefIdList) {
                    HashMap<String, String> rejectMap = new HashMap<>();
                    rejectMap.put("code", targetDefId);
                    UserTaskModel userTaskModelreject = SDK.getRepositoryAPI().getUserTaskModel(processDefId, targetDefId);
                    rejectMap.put("name", userTaskModelreject.getName());
                    rejectList.add(rejectMap);
                }
                approveMenu.setCode(commentId);
                approveMenu.setName(commentName);
                approveMenu.setRejectList(rejectList);
                approveMenus.add(approveMenu);
            }
        }
        return approveMenus;
    }

    /**
     * @methodName:
     * @param:
     * @return:
     * @description:流程刷新
     * @auther: Lizj
     * @date: 2022/8/29 0:53
     */
    public ResponseData refreshProcess(RequestData requestData, TaskInstance taskInstance) {
        //系统标识
        String applicationName = requestData.getApplicationName();
        //待办ID
        String outerId = requestData.getOuterId();
        //产品代码
        String fundCode = requestData.getFundCode();
        //扩展信息
        Map<String, String> extInfo = requestData.getExtInfo();

        ResponseData responseData = new ResponseData();

        String nowProcessDefId = taskInstance.getProcessDefId();
        String nowActivityDefId = taskInstance.getActivityDefId();
        UserTaskModel nowUserTaskModel = SDK.getRepositoryAPI().getUserTaskModel(nowProcessDefId, nowActivityDefId);
        List<CommentModel> nowCommentModels = nowUserTaskModel.getCommentModels();
        String targetUid = taskInstance.getTarget();
        String nodeName = nowUserTaskModel.getName();
        String title = taskInstance.getTitle();
        //审批菜单list
        ArrayList<ApproveMenu> approveMenus = new ArrayList<>();
        if (null!=nowCommentModels) {
            for (CommentModel commentModel : nowCommentModels) {
                ApproveMenu approveMenu = new ApproveMenu();
                //编码
                String commentId = commentModel.getId();
                //名称
                String commentName = commentModel.getActionName();
                //可驳回节点
                String targetDefIds = commentModel.getTargetDefId();
                ArrayList<String> targetDefIdList = new ArrayList<>();
                ArrayList<Map<String, String>> rejectList = new ArrayList<>();
                if (null!=targetDefIds && !targetDefIds.equals("")) {
                    if (targetDefIds.contains("%")) {
                        String[] targetDefIdsSplit1 = targetDefIds.split("%");
                        for (String targetDefIdSplit1 : targetDefIdsSplit1) {
                            if (targetDefIdSplit1.contains("|")) {
                                String[] targetDefIdsSplit2 = targetDefIdSplit1.split("\\|");
                                for (String targetDefIdSplit2 : targetDefIdsSplit2) {
                                    targetDefIdList.add(targetDefIdSplit2);
                                }
                            } else  {
                                if(null!=targetDefIdSplit1 && !targetDefIdSplit1.equals("")) {
                                    targetDefIdList.add(targetDefIdSplit1);
                                }
                            }
                        }
                    } else {
                        targetDefIds = targetDefIds.replace("|", "");
                        targetDefIdList.add(targetDefIds);
                    }
                }
                HashSet<String> targetDefIdSet = new HashSet<>();
                targetDefIdSet.addAll(targetDefIdList);
                targetDefIdList.clear();
                targetDefIdList.addAll(targetDefIdSet);
                for (String targetDefId : targetDefIdList) {
                    HashMap<String, String> rejectMap = new HashMap<>();
                    rejectMap.put("code", targetDefId);
                    UserTaskModel userTaskModelreject = SDK.getRepositoryAPI().getUserTaskModel(nowProcessDefId, targetDefId);
                    rejectMap.put("name", userTaskModelreject.getName());
                    rejectList.add(rejectMap);
                }
                approveMenu.setCode(commentId);
                approveMenu.setName(commentName);
                approveMenu.setRejectList(rejectList);
                approveMenus.add(approveMenu);
            }
        }
        //待办ID
        responseData.setOuterId(outerId);
        //办理人
        responseData.setTargetUid(targetUid);
        //环节名称
        responseData.setNodeName(nodeName);
        //环节编码
        responseData.setNodeCode(nowActivityDefId);
        //待办标题
        responseData.setTitle(title);
        //审核菜单
        responseData.setApproveMenu(approveMenus);
        //扩展信息
        responseData.setExtInfo(extInfo);

        return responseData;
    }

    /**通知消息
     * PC
     * @return*/
    public ResponseData notificationMessagePC(RequestData requestData) {
        //待办系统标识
        String applicationName = requestData.getApplicationName();
        //消息发送人ID
        String messageSender = requestData.getMessageSender();
        //消息接收人ID
        String messageRecipientId = requestData.getMessageRecipientId();
        //消息标题
        String messageTitle = requestData.getMessageTitle();
        //消息内容
        String messageContent = requestData.getMessageContent();
        //消息链接
        String messageUrl = requestData.getMessageUrl();
        //扩展信息
        Map<String, String> extInfo = requestData.getExtInfo();

        String msgContext = "消息标题：" + messageTitle + "\n" + "消息内容：" + messageContent + "\n" + "消息链接：" + messageUrl;
        SDK.getNotificationAPI().sendMessage(messageSender, messageRecipientId, msgContext);

        ResponseData responseData = new ResponseData();
        responseData.setExtInfo(extInfo);

        return responseData;
    }
    /**
     * weChat
     */
    public ResponseData notificationMessageWeChat(RequestData requestData) {
        //待办系统标识
        String applicationName = requestData.getApplicationName();
        //消息发送人ID
        //String messageSender = requestData.getMessageSender();
        //消息接收人ID
        String messageRecipientId = requestData.getMessageRecipientId();
        //消息标题
        String messageTitle = requestData.getMessageTitle();
        //消息内容
        String messageContent = requestData.getMessageContent();
        //消息链接
        String messageUrl = requestData.getMessageUrl();
        //扩展信息
        Map<String, String> extInfo = requestData.getExtInfo();

        //推送企业微信消息
        //获取调用接口凭证
        //corpid
        String corpid = SDK.getAppAPI().getProperty("com.actionsoft.apps.wechat", "wx-corpid");
        //agentId
        String agentid = SDK.getAppAPI().getProperty("com.actionsoft.apps.wechat", "agentId");
        //wx_corpsecret
        String corpsecret = SDK.getAppAPI().getProperty("com.actionsoft.apps.wechat", "wx_corpsecret");
        SendWechatMsgUtil sendWechatMsgUtil = new SendWechatMsgUtil();
        String accessToken = sendWechatMsgUtil.getAccessToken(corpid, corpsecret);
        //获取消息接收人
        String EXT1 = DBSql.getString("SELECT EXT1 FROM ORGUSER WHERE USERNO = ?", new Object[]{messageRecipientId});
        SDK.getLogAPI().consoleInfo("接收人账号：" + EXT1);
        if (null != EXT1 && !EXT1.equals("")) {

            //定义消息体参数
            String msgtype = "textcard";
            //是否开启id转译，0表示否，1表示是，默认0
            String enable_id_trans = "0";
            //表示是否开启重复消息检查，0表示否，1表示是，默认0
            String enable_duplicate_check = "0";
            //表示是否重复消息检查的时间间隔，默认1800s，最大不超过4小时
            String duplicate_check_interval = "1800";
           /* //定义消息内容
            String title = outerTitle;   //标题
            String description = "您有一个新的待办任务，来自【" + userName + "】"; //描述
            String url = finalBpmUrl;  //跳转链接
            String btntxt = "详情";  //按钮文字
            JSONObject textcard = new JSONObject();
            textcard.put("title", title);
            textcard.put("description", description);
            textcard.put("url", url);
            textcard.put("btntxt", btntxt);
            //定义消息体
            JSONObject para = new JSONObject();
            para.put("touser", EXT1);
            para.put("toparty", null);
            para.put("totag", null);
            para.put("msgtype", msgtype);
            para.put("agentid", agentid);
            para.put("textcard", textcard);
            para.put("enable_id_trans", enable_id_trans);
            para.put("enable_duplicate_check", enable_duplicate_check);
            para.put("duplicate_check_interval", duplicate_check_interval);
            sendWechatMsgUtil.sendAppMsg(accessToken, para);*/

        }
        return new ResponseData();
    }

    /**
     * @methodName: 流程取消（终止）
     * @param:
     * @return:
     * @description:
     * @auther: Lizj
     * @date: 2022/10/22 22:24
     */
    public ResponseData terminateProcess(RequestData requestData) {
        //流程实例ID
        String processInstId = requestData.getProcessInstId();
        //取消人
        String targetUid = requestData.getTargetUid();
        //取消原因
        String cancelReason = requestData.getCancelReason();
        //扩展信息
        Map<String, String> extInfo = requestData.getExtInfo();

        ResponseData responseData = new ResponseData();

        SDK.getProcessAPI().cancelById(processInstId, targetUid);

        responseData.setProcess_InstID(processInstId);
        responseData.setTargetUid(targetUid);
        responseData.setExtInfo(extInfo);

        return responseData;
    }
}


